<?php
class PNResearch extends PNObject {
  function PNResearch($init=null, $where='')
  {
    $this->PNObject();

    $this->_objType       = 'votepetition_research';
    $this->_objField      = 'id';
    $this->_objPath       = 'form';

    $this->_init($init, $where);
  }

  function insertPostProcess(){
    //$form = FormUtil::getPassedValue ('form', false);
    //$res_id = $this->objData['id'];
    $res_id = DBUtil::getInsertID ($this->_objType, $this->_objField);
    $person_in_house = FormUtil::getPassedValue ('person_in_house', false);
    $career_problem  = FormUtil::getPassedValue ('career_problem', false);
    $career_solve    = FormUtil::getPassedValue ('career_solve', false);
    $income          = FormUtil::getPassedValue ('income', false);
    $outlay          = FormUtil::getPassedValue ('outlay', false);
    $general_problem = FormUtil::getPassedValue ('general_problem', false);
    $general_solve   = FormUtil::getPassedValue ('general_solve', false);

    $career    = FormUtil::getPassedValue ('career', false);

    //var_dump($person_in_house); exit;
    //Check the person_in_house
      //Check exist user & topic
    $pntables = pnDBGetTables();


    $researchId = array( "res_id"=>$res_id);
    //var_dump($res_id); exit;
    if($person_in_house){
      // do the insert
      DBUtil::insertObjectArray($person_in_house, 'votepetition_person_in_house');
      $column = $pntables['votepetition_person_in_house_column'];
      $where = " $column[res_id] = 0 ";
      DBUtil::updateObject( $researchId, 'votepetition_person_in_house', $where);
    }

    //var_dump($res_id); exit;
    if($career){
      // do the insert
      DBUtil::insertObject($career, 'votepetition_career');
      $column = $pntables['votepetition_career_column'];
      $where = " $column[res_id] = 0 ";
      DBUtil::updateObject( $researchId, 'votepetition_career', $where);
    }

    //Check the career_problem
    if($career_problem){
      // do the insert
      DBUtil::insertObjectArray($career_problem, 'votepetition_career_problem');
      $column = $pntables['votepetition_career_problem_column'];
      $where = " $column[res_id] = 0 ";
      DBUtil::updateObject( $researchId, 'votepetition_career_problem', $where);
    }

    //Check the career_solve
    if($career_solve){
      // do the insert
      DBUtil::insertObjectArray($career_solve, 'votepetition_career_solve');
      $column = $pntables['votepetition_career_solve_column'];
      $where = " $column[res_id] = 0 ";
      DBUtil::updateObject( $researchId, 'votepetition_career_solve', $where);
    }

    //Check the income
    if($income){
      // do the insert
      DBUtil::insertObjectArray($income, 'votepetition_income');
      $column = $pntables['votepetition_income_column'];
      $where = " $column[res_id] = 0 ";
      DBUtil::updateObject( $researchId, 'votepetition_income', $where);
    }

    //Check the outlay
    if($outlay){
      // do the insert
      DBUtil::insertObjectArray($outlay, 'votepetition_outlay');
      $column = $pntables['votepetition_outlay_column'];
      $where = " $column[res_id] = 0 ";
      DBUtil::updateObject( $researchId, 'votepetition_outlay', $where);
    }

    //Check the general_problem
    if($general_problem){
      // do the insert
      DBUtil::insertObjectArray($general_problem, 'votepetition_general_problem');
      $column = $pntables['votepetition_general_problem_column'];
      $where = " $column[res_id] = 0 ";
      DBUtil::updateObject( $researchId, 'votepetition_general_problem', $where);
    }

    //Check the general_solve
    if($general_solve){
      // do the insert
      DBUtil::insertObjectArray($general_solve, 'votepetition_general_solve');
      $column = $pntables['votepetition_general_solve_column'];
      $where = " $column[res_id] = 0 ";
      DBUtil::updateObject( $researchId, 'votepetition_general_solve', $where);
    }
    //exit;
  }
}